library(car)
## Loading required package: carData
library(emmeans)
dd<-read.csv2("Ficusdata.csv")
head(dd)
##   Days   H
## 1    4 7.4
## 2    4 5.9
## 3    4 4.9
## 4    4 6.1
## 5    4 5.9
## 6    4 5.4

Descriptive:

dd$FDays<-as.factor(dd$Days)
sp(H~Days, dd)

head(dd)
##   Days   H FDays
## 1    4 7.4     4
## 2    4 5.9     4
## 3    4 4.9     4
## 4    4 6.1     4
## 5    4 5.9     4
## 6    4 5.4     4
summary(m1<-lm(H~Days, dd))
## 
## Call:
## lm(formula = H ~ Days, data = dd)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -9.6952 -2.8803 -0.4206  2.9469 13.3749 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.456364   0.511898  -0.892    0.374    
## Days         0.286780   0.006551  43.777   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.081 on 238 degrees of freedom
## Multiple R-squared:  0.8895, Adjusted R-squared:  0.8891 
## F-statistic:  1916 on 1 and 238 DF,  p-value: < 2.2e-16
plot(rstudent(m1),main="rstudent") 
abline(h=c(-3,0,3),lty=2)

for (i in 1:length(rstudent(m1))){
  if (rstudent(m1)[i] > 3) print(rstudent(m1)[i])
}
##      218 
## 3.188103 
##      230 
## 3.188103 
##      234 
## 3.372391
leveneTest(resid(m1)~dd$FDays)
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value    Pr(>F)    
## group   9   5.099 2.699e-06 ***
##       230                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(m1)

summary(m1f<-lm(H~Days+FDays, dd))
## 
## Call:
## lm(formula = H ~ Days + FDays, data = dd)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -8.0333 -1.2708 -0.0333  1.3156  7.1667 
## 
## Coefficients: (1 not defined because of singularities)
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  4.119312   0.478106   8.616 1.13e-15 ***
## Days         0.299339   0.005199  57.580  < 2e-16 ***
## FDays18     -2.236574   0.621842  -3.597 0.000394 ***
## FDays32     -5.948148   0.595739  -9.984  < 2e-16 ***
## FDays46     -7.230556   0.577682 -12.516  < 2e-16 ***
## FDays60     -8.358796   0.568439 -14.705  < 2e-16 ***
## FDays74     -9.170370   0.568439 -16.133  < 2e-16 ***
## FDays88     -9.565278   0.577682 -16.558  < 2e-16 ***
## FDays102    -7.518519   0.595739 -12.620  < 2e-16 ***
## FDays116    -4.142593   0.621842  -6.662 1.97e-10 ***
## FDays130           NA         NA      NA       NA    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.269 on 230 degrees of freedom
## Multiple R-squared:  0.967,  Adjusted R-squared:  0.9657 
## F-statistic: 748.8 on 9 and 230 DF,  p-value: < 2.2e-16
leveneTest(resid(m1f)~dd$FDays)
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value    Pr(>F)    
## group   9   5.099 2.699e-06 ***
##       230                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(m1f)

print(anova(m1, m1f))
## Analysis of Variance Table
## 
## Model 1: H ~ Days
## Model 2: H ~ Days + FDays
##   Res.Df    RSS Df Sum of Sq      F    Pr(>F)    
## 1    238 3963.8                                  
## 2    230 1184.2  8    2779.6 67.481 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
print(m1$coef[1]+m1$coef[2]*105)
## (Intercept) 
##    29.65557
predict(m1)[105]
##      105 
## 16.75045
emmeans(m1, ~Days)
##  Days   emmean        SE  df lower.CL upper.CL
##    67 18.75792 0.2634267 238 18.23897 19.27686
## 
## Confidence level used: 0.95
Days2 <- dd$Days^2
summary(m2<-lm(H~Days+I(Days^2), dd))
## 
## Call:
## lm(formula = H ~ Days + I(Days^2), data = dd)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -8.7770 -1.5422 -0.0596  1.3783  7.8653 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  6.2714174  0.4221346  14.856   <2e-16 ***
## Days        -0.0271203  0.0146695  -1.849   0.0657 .  
## I(Days^2)    0.0023425  0.0001058  22.133   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.335 on 237 degrees of freedom
## Multiple R-squared:  0.964,  Adjusted R-squared:  0.9637 
## F-statistic:  3171 on 2 and 237 DF,  p-value: < 2.2e-16
summary(m2f<-lm(H~Days+I(Days^2)+FDays, dd))
## 
## Call:
## lm(formula = H ~ Days + I(Days^2) + FDays, data = dd)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -8.0333 -1.2708 -0.0333  1.3156  7.1667 
## 
## Coefficients: (2 not defined because of singularities)
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  5.4931311  0.5323630  10.318  < 2e-16 ***
## Days        -0.0546840  0.0512325  -1.067   0.2869    
## I(Days^2)    0.0026420  0.0003966   6.662 1.97e-10 ***
## FDays18      1.9060185  0.8298322   2.297   0.0225 *  
## FDays32      1.3013889  1.1514892   1.130   0.2596    
## FDays46      2.0902778  1.3906000   1.503   0.1342    
## FDays60      1.9976852  1.4999794   1.332   0.1842    
## FDays74      1.1861111  1.4687543   0.808   0.4202    
## FDays88     -0.2444444  1.2974902  -0.188   0.8507    
## FDays102    -0.2689815  1.0007401  -0.269   0.7883    
## FDays116            NA         NA      NA       NA    
## FDays130            NA         NA      NA       NA    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.269 on 230 degrees of freedom
## Multiple R-squared:  0.967,  Adjusted R-squared:  0.9657 
## F-statistic: 748.8 on 9 and 230 DF,  p-value: < 2.2e-16
anova(m2, m2f)
## Analysis of Variance Table
## 
## Model 1: H ~ Days + I(Days^2)
## Model 2: H ~ Days + I(Days^2) + FDays
##   Res.Df    RSS Df Sum of Sq      F   Pr(>F)   
## 1    237 1292.4                                
## 2    230 1184.2  7    108.19 3.0018 0.004911 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(rstudent(m2),main="rstudent") 
abline(h=c(-2,0,2),lty=2)

for (i in 1:length(rstudent(m2))){
  if (rstudent(m2)[i] > 2) print(rstudent(m2)[i])
}
##       80 
## 2.086828 
##      200 
## 2.775014 
##      214 
## 2.105581 
##      218 
## 3.167343 
##      230 
## 3.167343 
##      234 
## 3.492016
leveneTest(resid(m2)~dd$FDays)
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value    Pr(>F)    
## group   9   5.099 2.699e-06 ***
##       230                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(m2)

#summary(m2)
predict(m2, new=data.frame(Days=0), se.fit=TRUE)
## $fit
##        1 
## 6.271417 
## 
## $se.fit
## [1] 0.4221346
## 
## $df
## [1] 237
## 
## $residual.scale
## [1] 2.335206
summary(m3<-lm(log(H)~Days, data = dd))
## 
## Call:
## lm(formula = log(H) ~ Days, data = dd)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.57837 -0.07874  0.01515  0.09263  0.35401 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 1.585522   0.019688   80.53   <2e-16 ***
## Days        0.016732   0.000252   66.41   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.157 on 238 degrees of freedom
## Multiple R-squared:  0.9488, Adjusted R-squared:  0.9486 
## F-statistic:  4410 on 1 and 238 DF,  p-value: < 2.2e-16
plot(rstudent(m3),main="rstudent") 
abline(h=c(-2,0,2),lty=2)

for (i in 1:length(rstudent(m3))){
  if (rstudent(m3)[i] > 2) print(rstudent(m3)[i])
}
##        1 
## 2.259143 
##       31 
## 2.145551 
##       45 
## 2.287293 
##       80 
## 2.185434
predict(m3, new=data.frame(Days=150), se.fit=TRUE)
## $fit
##        1 
## 4.095349 
## 
## $se.fit
## [1] 0.02323702
## 
## $df
## [1] 238
## 
## $residual.scale
## [1] 0.1569562
leveneTest(resid(m3)~dd$FDays)
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value    Pr(>F)    
## group   9  4.9414 4.476e-06 ***
##       230                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(m3)

summary(m4<-lm(sqrt(H)~Days, data = dd))
## 
## Call:
## lm(formula = sqrt(H) ~ Days, data = dd)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.90381 -0.23459 -0.00804  0.24907  0.87420 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 1.8614427  0.0421684   44.14   <2e-16 ***
## Days        0.0334581  0.0005396   62.00   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3362 on 238 degrees of freedom
## Multiple R-squared:  0.9417, Adjusted R-squared:  0.9415 
## F-statistic:  3844 on 1 and 238 DF,  p-value: < 2.2e-16
predict(m4, new=data.frame(Days=150), se.fit=TRUE)
## $fit
##        1 
## 6.880153 
## 
## $se.fit
## [1] 0.04977039
## 
## $df
## [1] 238
## 
## $residual.scale
## [1] 0.3361778
plot(rstudent(m4),main="rstudent") 
abline(h=c(-2,0,2),lty=2)

for (i in 1:length(rstudent(m4))){
  if (rstudent(m4)[i] > 2) print(rstudent(m4)[i])
}
##        1 
## 2.189593 
##      218 
## 2.497858 
##      230 
## 2.497858 
##      234 
## 2.652342
leveneTest(resid(m4)~dd$FDays)
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   9  1.1647 0.3187
##       230
plot(m4)

m3
## 
## Call:
## lm(formula = log(H) ~ Days, data = dd)
## 
## Coefficients:
## (Intercept)         Days  
##     1.58552      0.01673
summary(m5<-nls(H~exp(a+b*Days),start=list(a=1.58552,b=0.01673), data=dd))
## 
## Formula: H ~ exp(a + b * Days)
## 
## Parameters:
##    Estimate Std. Error t value Pr(>|t|)    
## a 1.5985554  0.0276060   57.91   <2e-16 ***
## b 0.0166774  0.0002487   67.05   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.264 on 238 degrees of freedom
## 
## Number of iterations to convergence: 2 
## Achieved convergence tolerance: 9.882e-08
predict(m5, new=data.frame(Days=0), se.fit=TRUE)
## [1] 4.945883
leveneTest(resid(m5)~dd$FDays)
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value    Pr(>F)    
## group   9   5.099 2.699e-06 ***
##       230                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
a=1.58552
b=0.01673
print(exp(a + b * 0))
## [1] 4.881829
logLik(m1)
## 'log Lik.' -677.0625 (df=3)
logLik(m2)
## 'log Lik.' -542.5799 (df=4)
logLik(m3)
## 'log Lik.' 104.8882 (df=3)
logLik(m4)
## 'log Lik.' -77.91342 (df=3)
logLik(m5)
## 'log Lik.' -535.6415 (df=3)
AIC(m2, m3)
##    df       AIC
## m2  4 1093.1597
## m3  3 -203.7764
AIC(m2, m4)
##    df       AIC
## m2  4 1093.1597
## m4  3  161.8268
AIC(m2, m5)
##    df      AIC
## m2  4 1093.160
## m5  3 1077.283
summary(m1)
## 
## Call:
## lm(formula = H ~ Days, data = dd)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -9.6952 -2.8803 -0.4206  2.9469 13.3749 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.456364   0.511898  -0.892    0.374    
## Days         0.286780   0.006551  43.777   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.081 on 238 degrees of freedom
## Multiple R-squared:  0.8895, Adjusted R-squared:  0.8891 
## F-statistic:  1916 on 1 and 238 DF,  p-value: < 2.2e-16
summary(m2)
## 
## Call:
## lm(formula = H ~ Days + I(Days^2), data = dd)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -8.7770 -1.5422 -0.0596  1.3783  7.8653 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  6.2714174  0.4221346  14.856   <2e-16 ***
## Days        -0.0271203  0.0146695  -1.849   0.0657 .  
## I(Days^2)    0.0023425  0.0001058  22.133   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.335 on 237 degrees of freedom
## Multiple R-squared:  0.964,  Adjusted R-squared:  0.9637 
## F-statistic:  3171 on 2 and 237 DF,  p-value: < 2.2e-16
summary(m3)
## 
## Call:
## lm(formula = log(H) ~ Days, data = dd)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.57837 -0.07874  0.01515  0.09263  0.35401 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 1.585522   0.019688   80.53   <2e-16 ***
## Days        0.016732   0.000252   66.41   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.157 on 238 degrees of freedom
## Multiple R-squared:  0.9488, Adjusted R-squared:  0.9486 
## F-statistic:  4410 on 1 and 238 DF,  p-value: < 2.2e-16
summary(m4)
## 
## Call:
## lm(formula = sqrt(H) ~ Days, data = dd)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.90381 -0.23459 -0.00804  0.24907  0.87420 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 1.8614427  0.0421684   44.14   <2e-16 ***
## Days        0.0334581  0.0005396   62.00   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3362 on 238 degrees of freedom
## Multiple R-squared:  0.9417, Adjusted R-squared:  0.9415 
## F-statistic:  3844 on 1 and 238 DF,  p-value: < 2.2e-16
leveneTest(resid(m1)~dd$FDays)
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value    Pr(>F)    
## group   9   5.099 2.699e-06 ***
##       230                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
leveneTest(resid(m2)~dd$FDays)
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value    Pr(>F)    
## group   9   5.099 2.699e-06 ***
##       230                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
leveneTest(resid(m3)~dd$FDays)
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value    Pr(>F)    
## group   9  4.9414 4.476e-06 ***
##       230                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
leveneTest(resid(m4)~dd$FDays)
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value Pr(>F)
## group   9  1.1647 0.3187
##       230
leveneTest(resid(m5)~dd$FDays)
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value    Pr(>F)    
## group   9   5.099 2.699e-06 ***
##       230                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
dias = 0
print(m1$coef[1]+m1$coef[2]*dias)
## (Intercept) 
##  -0.4563636
print(m2$coef[1]+m2$coef[2]*dias+m2$coef[3]*dias^2)
## (Intercept) 
##    6.271417
print(exp(m3$coef[1]+m3$coef[2]*dias))
## (Intercept) 
##     4.88184
print((m4$coef[1]+m4$coef[2]*dias)^2)
## (Intercept) 
##    3.464969
a=1.58552
b=0.01673
print(exp(a + b * dias))
## [1] 4.881829
dias = 105
predict(m1, new=data.frame(Days=dias), se.fit=TRUE)[4]
## $residual.scale
## [1] 4.080989
predict(m2, new=data.frame(Days=dias), se.fit=TRUE)[4]
## $residual.scale
## [1] 2.335206
predict(m3, new=data.frame(Days=dias), se.fit=TRUE)[4]
## $residual.scale
## [1] 0.1569562
predict(m4, new=data.frame(Days=dias), se.fit=TRUE)[4]
## $residual.scale
## [1] 0.3361778
predict(m5, new=data.frame(Days=dias), se.fit=TRUE)[4]
## [1] NA
# 2.264